package com.happy.film.service.impl;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happy.film.entity.Tags;
import com.happy.film.entity.dto.TagDto;
import com.happy.film.entity.dto.TagVo;
import com.happy.film.mapper.TagsMapper;
import com.happy.film.service.ITagsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wei.zhang
 * @since 2020-03-17
 */
@Service
public class TagsServiceImpl extends ServiceImpl<TagsMapper, Tags> implements ITagsService {

    @Override
    public List<TagVo> searchTags(TagDto tagDto) {
        IPage<Tags> page = new Page<>(tagDto.getPageNo(),tagDto.getPageSize());
        page = this.baseMapper.selectPage(page,new QueryWrapper<>());

        return page.getRecords().stream().map(tags -> {
            TagVo tagVo = new TagVo();
            BeanUtils.copyProperties(tags,tagVo);
            return tagVo;
        }).collect(Collectors.toList());
    }
}
